package com.zh.note.huawei.onehundred.英文输入法;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * @Author: zhanghuan
 * @date: 2023/8/31 20:52
 * @description: create it
 * <p>
 * The furthest distance in the world, Is not between life and death, But when I stand in front of you, Yet you don’t know that I love you.
 * f
 */

public class Main {

    public static void solve(String value, String targetStr) {
        if (value == null || value.length() == 0) {
            System.out.println("input error");
            return;
        }
        List<String> myList = new ArrayList<>();
        StringBuilder wordSb = new StringBuilder();
        for (int j = 0; j < value.length(); ++j) {
            char ch = value.charAt(j);
            if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) {
                wordSb.append(ch);
            } else {
                myList.add(wordSb.toString());
                wordSb = new StringBuilder();
            }
        }
        myList.add(wordSb.toString());
        List<String> resultList = new ArrayList<>();
        for (int j = 0; j < myList.size(); ++j) {
            String s = myList.get(j);
            if (s.startsWith(targetStr)) {
                resultList.add(myList.get(j));
            }
        }
        //排序
        Collections.sort(resultList);
        if (resultList.size() > 0) {
            for (int j = 0; j < resultList.size(); ++j) {
                String reslut = resultList.get(j) + " ";
                System.out.print(reslut);
            }
            System.out.println();
        } else {
            System.out.println(targetStr);
        }
    }

    public static void main(String[] args) {
        try {
            Scanner s = new Scanner(System.in);
            String value = s.nextLine();
            String targetStr = s.nextLine();
            solve(value, targetStr);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("input error");
        }
    }
}
